<template>
  <div class="header">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>{{ this.$route.meta.title }}</el-breadcrumb-item>
    </el-breadcrumb>

    <el-dropdown>
      <span class="el-dropdown-link">
       <span @click="toLogin">{{username}}</span><i class="el-icon-arrow-down el-icon--right"></i>
      </span>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item v-if="username!='登录'"><span @click="clearUserInfo">退出登录</span></el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
import {mapMutations} from 'vuex'
export default {
  data(){
    return{
      username:''
    }
  },
  methods:{
    ...mapMutations(['clearUserInfo']),
    toLogin(){
      if(this.username==='登录'){
        this.$router.push('/login')
      }
    }
  },
  created(){
    this.username=localStorage.getItem('userInfo')?JSON.parse(localStorage.getItem('userInfo')).username:'登录'
  }
};
</script>
<style scoped>
.header{
  display: flex;
  justify-content: space-between;
  padding-top: 20px;
}

</style>